@echo off
echo 开始编译 GB28181 客户端示例...
echo 检测到Windows环境

:: 检查系统库
echo 检查系统库...
where g++ >nul 2>&1
if errorlevel 1 (
    echo 错误: g++编译器未找到！请确保已安装MinGW或MSYS2，并且g++在PATH中。
    exit /b 1
)

:: 设置编译目录
if not exist direct_build mkdir direct_build

:: 编译命令
set COMPILE_CMD=g++ -std=c++11 -I. -Isrc -std=c++11 -I/usr/include/opencv -I/usr/include/ffmpeg -I/usr/include/ffmpeg -I/usr/include/ffmpeg -I/usr/include/ffmpeg -I/usr/local/include -DPJ_AUTOCONF=1 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1

:: 源文件
set SRC_FILES=src/Application.cpp src/Config.cpp src/Logger.cpp src/main.cpp src/SipManager.cpp src/StreamManager.cpp src/XmlHelper.cpp

:: 输出文件
set OUTPUT=direct_build/gb_client.exe

:: 链接库
set LIBS=-lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_video -lopencv_plot -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core -lavcodec -lavformat -lavutil -lswscale -L/usr/local/lib -lpjsua2 -lstdc++ -lpjsua -lpjsip-ua -lpjsip-simple -lpjsip -lpjmedia-codec -lpjmedia-videodev -lpjmedia-audiodev -lpjmedia -lpjnath -lpjlib-util -lpj -lpthread -lm -lstdc++ -lrt

echo 使用以下命令编译:
echo %COMPILE_CMD% %SRC_FILES% -o %OUTPUT% %LIBS%

%COMPILE_CMD% %SRC_FILES% -o %OUTPUT% %LIBS%

if errorlevel 1 (
    echo 编译失败，请检查错误信息。
    exit /b 1
) else (
    echo 编译成功！
    echo 现在可以运行: %OUTPUT%
    
    :: 复制测试视频
    if exist test.mp4 (
        copy test.mp4 direct_build\
        echo 已复制测试视频到direct_build目录
    )
    
    :: 创建可执行文件链接或副本
    copy direct_build\gb_client.exe .
    echo 已创建 gb_client.exe 在当前目录
    
    :: 检查测试视频文件
    if exist test.mp4 (
        echo 检测到 test.mp4 测试视频文件。
    ) else (
        echo 警告: 未检测到 test.mp4 测试视频文件，请确保有测试视频文件以便进行推流测试。
    )
)

exit /b 0 